package com.songshuai.webapi.permission.controller;

import com.songshuai.webapi.baseapi.enumerations.ResultStatus;
import com.songshuai.webapi.baseapi.pojo.QueryResponse;
import com.songshuai.webapi.baseapi.utils.RequestParamValidUtil;
import com.songshuai.webapi.permission.dto.request.*;
import com.songshuai.webapi.permission.service.RoleUserService;
import com.songshuai.webapi.permission.service.RolesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.Map;

@Api("角色用户管理")
@Slf4j
@RestController
@RequestMapping("/api/roles/")
public class RoleUserController {

  // @Autowired
   // private RolesService rolesService;

    @Autowired
    private RoleUserService roleUserService;

   /* @PostMapping("queryUserList")
    public QueryResponse<Map<String,Object>> queryUserList(@RequestBody @Valid  RoleUserListReqDto roleUserListReqDto, BindingResult result){
        if (result.hasErrors()){
            return new QueryResponse(ResultStatus.ERROR_INVALID_ARGUMENT.getErrorCode(), RequestParamValidUtil.getBindingResultMessage(result));
        }
        try {
            return rolesService.queryUserList(roleUserListReqDto);
        } catch (Exception e) {
            log.error("api/roles/queryUserList",e);
            //return new QueryResponse(ResultStatus.FAIL.getErrorCode(), e.getMessage());
            return new QueryResponse(ResultStatus.HTTP_STATUS_INTERNAL_SERVER_ERROR);
        }
        //return new QueryResponse(ResultStatus.ERROR_SEARCH_FAILED);
    }*/





    /*@ApiOperation(value = "给角色分配人员")
    @PostMapping("insertRoleUsers")
    public QueryResponse insertRoleUsers(@RequestBody @Valid  RoleUserReqDto roleUserReqDto, BindingResult result){
        if (result.hasErrors()){
            return new QueryResponse(ResultStatus.ERROR_INVALID_ARGUMENT.getErrorCode(), RequestParamValidUtil.getBindingResultMessage(result));
        }
        try {
            return rolesService.insertRoleUsers(roleUserReqDto);
        } catch (Exception e) {
            log.error("api/roles/insertRoleUsers",e);
            return new QueryResponse(ResultStatus.HTTP_STATUS_INTERNAL_SERVER_ERROR);
           // return new QueryResponse(ResultStatus.ERROR_CREATE_FAILED);
        }
    }*/


    /**
     * 分配人员下拉框，快速定位到人员
     * @param quickPositioningUserReqDto
     * @param result
     * @return
     */
    @PostMapping("quickPositioningUser")
    public QueryResponse<Map<String,Object>> quickPositioningUser(@RequestBody @Valid QuickPositioningUserReqDto quickPositioningUserReqDto, BindingResult result){
        if (result.hasErrors()){
            return new QueryResponse(ResultStatus.ERROR_INVALID_ARGUMENT.getErrorCode(), RequestParamValidUtil.getBindingResultMessage(result));
        }
        try {
            return roleUserService.quickPositioningUser(quickPositioningUserReqDto);
        } catch (Exception e) {
            log.error("api/roles/quickPositioningUser",e);
            //return new QueryResponse(ResultStatus.FAIL.getErrorCode(), e.getMessage());
            return new QueryResponse(ResultStatus.HTTP_STATUS_INTERNAL_SERVER_ERROR);
        }
        //return new QueryResponse(ResultStatus.ERROR_SEARCH_FAILED);
    }






}
